#delimit ;
set more 1;
log using "/volumes/ddisk/math/soviet/Table_6.log", replace;


use "/volumes/ddisk/math/ams/clean_ams_data_author_year.dta", replace;

generate good=.;
replace good=1 if year>=1970 & year<=1989;
egen n70=sum(good*papers), by(unique);
drop if n70==0;

merge unique using "/volumes/ddisk/math/ams/international/soviet_universe.dta";
drop _merge;

keep if soviet==1;
drop if emigre==1;

drop country;
rename modal_country country;

keep if year>=1982 & year<=2008;

sort unique;
merge unique using /volumes/ddisk/math/soviet/shocks_and_instruments.dta;
drop _merge;

drop if shock_idea_space==.;

generate publish=(papers>0);
summ publish papers ;


generate inter_shock1=post1992*shock_idea_space;
generate inter_pexp1=post1992*shock_geographic_space;
generate inter_paut1=post1992*shock_coauthor_space;
replace inter_paut1=0 if inter_paut1==.;

generate inst_shock1=post1992*instrument_idea_space;
generate inst_pexp1=post1992*instrument_geographic_space;
generate inst_paut1=post1992*instrument_coauthor_space;
replace inst_paut1=0 if inst_paut1==.;

replace shock_coauthor_space_high=0 if shock_coauthor_space_high==.;
replace shock_coauthor_space_low=0 if shock_coauthor_space_low==.;
replace instrument_coauthor_space_high=0 if instrument_coauthor_space_high==.;
replace instrument_coauthor_space_low=0 if instrument_coauthor_space_low==.;


generate inter_shock_coauthor_high=post1992*shock_coauthor_space_high;
generate inter_shock_coauthor_low=post1992*shock_coauthor_space_low;

generate inst_high=post1992*instrument_coauthor_space_high;
generate inst_low=post1992*instrument_coauthor_space_low;



xtivreg2 publish post1992 exper* dyear* 
	(inter_shock_coauthor_high inter_shock_coauthor_low =
	inst_high inst_low), 
	fe i(unique) cluster(unique);
xtivreg2 papers post1992 exper* dyear* 
	(inter_shock_coauthor_high inter_shock_coauthor_low =
	inst_high inst_low), 
	fe i(unique) cluster(unique);

xtivreg2 publish post1992 exper* dyear* 
	(inter_shock1 inter_pexp1 inter_shock_coauthor_high inter_shock_coauthor_low=
	inst_shock1 inst_pexp1 inst_high inst_low) , 
	fe i(unique) cluster(unique);
xtivreg2 papers post1992 exper* dyear* 
	(inter_shock1 inter_pexp1 inter_shock_coauthor_high inter_shock_coauthor_low=
	inst_shock1 inst_pexp1 inst_high inst_low) , 
	fe i(unique) cluster(unique);


save /volumes/ddisk/data/junkdata.dta, replace;


*NOW THE REGRESSION ON PAPERS WRITTEN WITH NON-EMIGRES;
*KIRK CREATED THE NON_EMIGRE_PAPERS DATA SET THAT IS THE DEPENDENT VARIABLE;

sort unique year;
merge unique year using /volumes/ddisk/math/soviet/non_emigre_papers.dta;
drop _merge;

drop if unique==.;
replace non_emigre_papers=0 if non_emigre_papers==.;

generate net_papers= non_emigre_papers;
summ net_papers, detail;
generate net_publish=(net_papers>0);


xtivreg2 net_publish post1992 exper* dyear* 
	(inter_shock1 inter_pexp1 inter_shock_coauthor_high inter_shock_coauthor_low=
	inst_shock1 inst_pexp1 inst_high inst_low) , 
	fe i(unique) cluster(unique);
xtivreg2 net_papers post1992 exper* dyear* 
	(inter_shock1 inter_pexp1 inter_shock_coauthor_high inter_shock_coauthor_low=
	inst_shock1 inst_pexp1 inst_high inst_low) , 
	fe i(unique) cluster(unique);
	

*****************;

*MERGING IN DATA THAT HAS DEPENDENT VARIABLES "TOP JOURNALS" AND "COAUTHOR SHARE";
*REGRESSION IN COLUMN 3 OF TABLE 6;
*REGRESSIONS WILL BE RUN USING TWO SPECIFICATIONS;
*MISSING WILL BE TREATED AS MISSING OR SET TO ZERO;



sort unique year;
merge unique year using /volumes/ddisk/math/soviet/hard_outcome_variables.dta;
drop _merge;

rename author_share_papers share_of_papers;

xtivreg2 share_of_papers post1992 exper* dyear* 
	(inter_shock1 inter_pexp1 inter_shock_coauthor_high inter_shock_coauthor_low=
	inst_shock1 inst_pexp1 inst_high inst_low) , 
	fe i(unique) cluster(unique);

replace share_of_papers=0 if share_of_papers==.;

xtivreg2 share_of_papers post1992 exper* dyear* 
	(inter_shock1 inter_pexp1 inter_shock_coauthor_high inter_shock_coauthor_low=
	inst_shock1 inst_pexp1 inst_high inst_low) , 
	fe i(unique) cluster(unique);
	
log close;



